﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x0200056F RID: 1391
	public class PauseRegistrationList : MonoBehaviour
	{
		// Token: 0x1700044B RID: 1099
		// (get) Token: 0x06002388 RID: 9096 RVA: 0x000D6314 File Offset: 0x000D4514
		// (set) Token: 0x06002389 RID: 9097 RVA: 0x000D631C File Offset: 0x000D451C
		public OCIChar ociChar
		{
			get
			{
				return this.m_OCIChar;
			}
			set
			{
				this.m_OCIChar = value;
				if (this.m_OCIChar != null)
				{
					this.InitList();
				}
			}
		}

		// Token: 0x1700044C RID: 1100
		// (get) Token: 0x0600238A RID: 9098 RVA: 0x000D6338 File Offset: 0x000D4538
		// (set) Token: 0x0600238B RID: 9099 RVA: 0x000D6348 File Offset: 0x000D4548
		public bool active
		{
			get
			{
				return base.gameObject.activeSelf;
			}
			set
			{
				if (base.gameObject.activeSelf != value)
				{
					base.gameObject.SetActive(value);
				}
			}
		}

		// Token: 0x0600238C RID: 9100 RVA: 0x000D6368 File Offset: 0x000D4568
		private void OnClickClose()
		{
			base.gameObject.SetActive(false);
		}

		// Token: 0x0600238D RID: 9101 RVA: 0x000D6378 File Offset: 0x000D4578
		private void OnEndEditName(string _text)
		{
			this.buttonSave.interactable = !_text.IsNullOrEmpty();
		}

		// Token: 0x0600238E RID: 9102 RVA: 0x000D6390 File Offset: 0x000D4590
		private void OnClickSave()
		{
			PauseCtrl.Save(this.ociChar, this.inputName.text);
			this.InitList();
		}

		// Token: 0x0600238F RID: 9103 RVA: 0x000D63B0 File Offset: 0x000D45B0
		private void OnClickLoad()
		{
			PauseCtrl.Load(this.ociChar, this.listPath[this.select]);
		}

		// Token: 0x06002390 RID: 9104 RVA: 0x000D63D0 File Offset: 0x000D45D0
		private void OnClickDelete()
		{
			CheckScene.sprite = this.spriteDelete;
			CheckScene.unityActionYes = new UnityAction(this.OnSelectDeleteYes);
			CheckScene.unityActionNo = new UnityAction(this.OnSelectDeleteNo);
			Singleton<Scene>.Instance.Load(new Scene.Data
			{
				sceneName = "StudioCheck",
				isLoading = false,
				isAsync = false,
				isFade = false,
				isOverlap = false,
				isAdd = true
			});
		}

		// Token: 0x06002391 RID: 9105 RVA: 0x000D644C File Offset: 0x000D464C
		private void OnSelectDeleteYes()
		{
			Singleton<Scene>.Instance.UnLoad();
			File.Delete(this.listPath[this.select]);
			this.InitList();
		}

		// Token: 0x06002392 RID: 9106 RVA: 0x000D6478 File Offset: 0x000D4678
		private void OnSelectDeleteNo()
		{
			Singleton<Scene>.Instance.UnLoad();
		}

		// Token: 0x06002393 RID: 9107 RVA: 0x000D6488 File Offset: 0x000D4688
		private void OnClickSelect(int _no)
		{
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(this.select, out studioNode))
			{
				studioNode.select = false;
			}
			this.select = _no;
			if (this.dicNode.TryGetValue(this.select, out studioNode))
			{
				studioNode.select = true;
			}
			if (this.select != -1)
			{
				this.buttonLoad.interactable = true;
				this.buttonDelete.interactable = true;
			}
		}

		// Token: 0x06002394 RID: 9108 RVA: 0x000D6500 File Offset: 0x000D4700
		private void InitList()
		{
			for (int i = 0; i < this.transformRoot.childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			this.select = -1;
			this.buttonLoad.interactable = false;
			this.buttonDelete.interactable = false;
			int sex = this.m_OCIChar.oiCharInfo.sex;
			this.listPath = (from v in Directory.GetFiles(UserData.Create("studio/pose"), "*.dat")
			where PauseCtrl.CheckIdentifyingCode(v, sex)
			select v).ToList<string>();
			this.dicNode.Clear();
			for (int j = 0; j < this.listPath.Count; j++)
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.prefabNode);
				gameObject.transform.SetParent(this.transformRoot, false);
				StudioNode component = gameObject.GetComponent<StudioNode>();
				component.active = true;
				int no = j;
				component.addOnClick = delegate()
				{
					this.OnClickSelect(no);
				};
				component.text = PauseCtrl.LoadName(this.listPath[j]);
				this.dicNode.Add(j, component);
			}
		}

		// Token: 0x06002395 RID: 9109 RVA: 0x000D6664 File Offset: 0x000D4864
		private void Awake()
		{
			this.buttonClose.onClick.AddListener(new UnityAction(this.OnClickClose));
			this.inputName.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditName));
			this.buttonSave.onClick.AddListener(new UnityAction(this.OnClickSave));
			this.buttonSave.interactable = false;
			this.buttonLoad.onClick.AddListener(new UnityAction(this.OnClickLoad));
			this.buttonDelete.onClick.AddListener(new UnityAction(this.OnClickDelete));
		}

		// Token: 0x0400247A RID: 9338
		[SerializeField]
		private Button buttonClose;

		// Token: 0x0400247B RID: 9339
		[SerializeField]
		private InputField inputName;

		// Token: 0x0400247C RID: 9340
		[SerializeField]
		private Button buttonSave;

		// Token: 0x0400247D RID: 9341
		[SerializeField]
		private Button buttonLoad;

		// Token: 0x0400247E RID: 9342
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x0400247F RID: 9343
		[SerializeField]
		private GameObject prefabNode;

		// Token: 0x04002480 RID: 9344
		[SerializeField]
		private Button buttonDelete;

		// Token: 0x04002481 RID: 9345
		[SerializeField]
		private Sprite spriteDelete;

		// Token: 0x04002482 RID: 9346
		private OCIChar m_OCIChar;

		// Token: 0x04002483 RID: 9347
		private List<string> listPath;

		// Token: 0x04002484 RID: 9348
		private Dictionary<int, StudioNode> dicNode = new Dictionary<int, StudioNode>();

		// Token: 0x04002485 RID: 9349
		private int select = -1;
	}
}
